//创建缓冲区
let fs = require("fs");

//读取文件夹
let dir = fs.readdirSync(__dirname);
console.log(dir)

dir.forEach((value, index, array) => {
    //判断是否为文件
    let stats = fs.lstatSync(__dirname + "/" + value);
    if (stats.isDirectory() === false) {
        //读取文件
        let buffer = fs.readFileSync(__dirname + "/" + value);
        console.log(buffer.length)
    }

})


let fileBuffer = fs.readFileSync("./1669705150225.jpg");
console.log(fileBuffer.length)


//字符字符串创建缓冲区
let byteArr = Buffer.from("hello", "latin1");

console.log(typeof byteArr)
console.log(byteArr.toJSON()) //{ type: 'Buffer', data: [ 104, 101, 108, 108, 111 ] }
console.log(Buffer.byteLength(byteArr))

// buffer拼接

let sourceBuffer = Buffer.alloc(4);
let target = Buffer.from("abcd");
console.log(target)
sourceBuffer.fill(target,0,4)
console.log(sourceBuffer)


